//
//  S1mpl3HeadView.m
//  沙哈拉FM
//
//  Created by dllo on 15/11/5.
//  Copyright © 2015年 S1mpl3. All rights reserved.
//

#import "S1mpl3HeadView.h"
#import "FitHeader.h"
#import "UIImageView+WebCache.h"
#import "UIImage+GaussianBlur.h"


@implementation S1mpl3HeadView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatView];
    }
    return self;
}

-(void)creatView{
    _backImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -100, 375, 350)];
    [self addSubview:_backImageView];
    
    _leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20 * FITWidth, 50 * FITHeight, 100 * FITWidth, 120 * FITHeight)];
    [self addSubview:_leftImageView];
    
    _headImageView = [[UIImageView alloc] initWithFrame:CGRectMake(_leftImageView.frame.origin.x + _leftImageView.frame.size.width + 20, 40 * FITHeight, 30 * FITHeight, 30 * FITHeight)];
    _headImageView.layer.cornerRadius = 15 * FITHeight;
    _headImageView.layer.masksToBounds = YES;
    [self addSubview:_headImageView];
    
    _logoLabel = [[BaseLabel alloc] initWithFrame:CGRectMake(_headImageView.frame.origin.x + _headImageView.frame.size.width, _headImageView.frame.origin.y, 100 * FITWidth, _headImageView.frame.size.height)];
    _logoLabel.textColor = [UIColor whiteColor];
    [self addSubview:_logoLabel];
    
    _contentLabel = [[BaseLabel alloc] initWithFrame:CGRectMake(_headImageView.frame.origin.x, _headImageView.frame.origin.y + _headImageView.frame.size.height +  20 * FITHeight, 200 * FITWidth, 20 * FITHeight)];
    _contentLabel.textColor = [UIColor lightGrayColor];
    [self addSubview:_contentLabel];
    
    _moreImageView = [[UIImageView alloc] initWithFrame:CGRectMake(_contentLabel.frame.origin.x + _contentLabel.frame.size.width, _contentLabel.frame.origin.y, 22 * FITHeight, 22 * FITHeight)];
    _moreImageView.image = [UIImage imageNamed:@"S1mpl3更多"];
    [self addSubview:_moreImageView];
    
    _hLineLabel = [[BaseLabel alloc] initWithFrame:CGRectMake(0, _leftImageView.frame.origin.y + _leftImageView.frame.size.height + 28 * FITHeight, self.frame.size.width, 1)];
    _hLineLabel.backgroundColor = [UIColor lightGrayColor];
    [self addSubview:_hLineLabel];
    
    _loveImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20 * FITWidth, _hLineLabel.frame.origin.y + _hLineLabel.frame.size.height + 15 * FITHeight, 20 * FITHeight, 20 * FITHeight)];
    _loveImageView.image = [UIImage imageNamed:@"S1mpl3Head收藏"];
    [self addSubview:_loveImageView];
    
    _loveLabel = [[BaseLabel alloc] initWithFrame:CGRectMake(_loveImageView.frame.origin.x + _loveImageView.frame.size.width + 4 * FITWidth, _loveImageView.frame.origin.y - 5 * FITHeight, 90 * FITWidth, 30 * FITHeight)];
    _loveLabel.textColor = [UIColor whiteColor];
    [_loveLabel setFontSize:15];
    _loveLabel.text = @"收藏";
    [self addSubview:_loveLabel];
    
    _sLeftLineLabel = [[BaseLabel alloc] initWithFrame:CGRectMake(_loveLabel.frame.origin.x + _loveLabel.frame.size.width, _loveLabel.frame.origin.y + 5 * FITHeight, 1 , 30 * FITHeight)];
    _sLeftLineLabel.backgroundColor = [UIColor lightGrayColor];
    [self addSubview:_sLeftLineLabel];
    
    _downloadImageView = [[UIImageView alloc] initWithFrame:CGRectMake(_sLeftLineLabel.frame.origin.x + _sLeftLineLabel.frame.size.width + 10 * FITWidth, _loveImageView.frame.origin.y, _loveImageView.frame.size.width, _loveImageView.frame.size.height)];
    _downloadImageView.image = [UIImage imageNamed:@"S1mpl3Head下载"];
    [self addSubview:_downloadImageView];
    
    _downloadLabel = [[BaseLabel alloc] initWithFrame:CGRectMake(_downloadImageView.frame.origin.x + _downloadImageView.frame.size.width + 4 * FITWidth, _downloadImageView.frame.origin.y - 5 * FITHeight, _loveLabel.frame.size.width, _loveLabel.frame.size.height)];
    _downloadLabel.text = @"批量下载";
    [_downloadLabel setFontSize:15];
    _downloadLabel.textColor = [UIColor whiteColor];
    [self addSubview:_downloadLabel];
    
    _sRightLineLabel = [[BaseLabel alloc] initWithFrame:CGRectMake(_downloadLabel.frame.origin.x + _downloadLabel.frame.size.width, _downloadLabel.frame.origin.y + 5 * FITHeight, _sLeftLineLabel.frame.size.width , _sLeftLineLabel.frame.size.height)];
    _sRightLineLabel.backgroundColor = [UIColor lightGrayColor];
    [self addSubview:_sRightLineLabel];
    
    _aboutImageView = [[UIImageView alloc] initWithFrame:CGRectMake(_sRightLineLabel.frame.origin.x + _sRightLineLabel.frame.size.width + 10 * FITWidth, _loveImageView.frame.origin.y, _loveImageView.frame.size.width, _loveImageView.frame.size.height)];
    _aboutImageView.image = [UIImage imageNamed:@"S1mpl3Head相关"];
    [self addSubview:_aboutImageView];
    
    _aboutLabel = [[BaseLabel alloc] initWithFrame:CGRectMake(_aboutImageView.frame.origin.x + _aboutImageView.frame.size.width + 4 * FITWidth, _aboutImageView.frame.origin.y, _loveLabel.frame.size.width - 5 * FITHeight, _loveLabel.frame.size.height)];
    _aboutLabel.text = @"相关推荐";
    [_aboutLabel setFontSize:15];
    _aboutLabel.textColor = [UIColor whiteColor];
    [self addSubview:_aboutLabel];
}

-(void)setDataSourceDic:(NSMutableDictionary *)dataSourceDic{
//    [_backImageView sd_setImageWithURL:[NSURL URLWithString:[dataSourceDic objectForKey:@"coverLarge"]] placeholderImage:[UIImage imageNamed:@""]];
    _backImageView.image = [UIImage imageWithBlurImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[dataSourceDic objectForKey:@"coverLarge"]]]] intputRadius:30];
    [_leftImageView sd_setImageWithURL:[NSURL URLWithString:[dataSourceDic objectForKey:@"coverOrigin"]] placeholderImage:[UIImage imageNamed:@""]];
    
    [_headImageView sd_setImageWithURL:[NSURL URLWithString:[dataSourceDic objectForKey:@"avatarPath"]] placeholderImage:[UIImage imageNamed:@""]];
    
    _logoLabel.text = [dataSourceDic objectForKey:@"nickname"];
    
    _contentLabel.text = [dataSourceDic objectForKey:@"intro"];
    
    NSString *tags = [dataSourceDic objectForKey:@"tags"];
    if (tags.length !=0 ) {
        NSArray *array = [tags componentsSeparatedByString:@","];
        for (NSInteger i = 0; i < 3; i++) {
            BaseLabel *label = [[BaseLabel alloc] initWithFrame:CGRectMake(_contentLabel.frame.origin.x + 75 * FITWidth * i, _contentLabel.frame.origin.y + _contentLabel.frame.size.height + 15 * FITHeight, 65 * FITWidth, 25 * FITHeight)];
            label.layer.borderWidth = 1;
            label.layer.cornerRadius = 7 * FITHeight;
            [label setFontSize:14];
            label.textAlignment = 1;
            label.layer.borderColor = [UIColor lightGrayColor].CGColor;
            label.text = array[i];
            label.textColor = [UIColor lightGrayColor];
            [self addSubview:label];
        }

    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
